package com.atguigu.day05.test;

import java.util.Arrays;

/**
 * @version 1.0
 * @Author 马冰
 * @Date 2024/11/4 16:29
 * @注释
 */
public class ArrayTest08 {
    public static void main(String[] args) {
        int[] arr = {10, 20, 30, 40, 50, 60, 70};
        System.out.println("反转前:" + Arrays.toString(arr));
        //第一种方法
        /*int[] arr2 = new int[arr.length];
        for (int i = arr.length - 1; i >= 0; i--) {
            arr2[arr.length - 1 - i] = arr[i];
        }
        arr = arr2;*/

        //第二种方法
        int ar = 0;
        for (int i = 0; i < arr.length / 2; i++) {
            ar = arr[i];
            arr[i] = arr[arr.length - 1 - i];
            arr[arr.length - 1 - i] = ar;
        }




        System.out.println("反转后:" + Arrays.toString(arr));
    }
}
